<%--
   processVariable
   Copyright (c) 2014 ISPERP
   Version : 1.0.0
 --%>
<%@ tag language="java" pageEncoding="UTF-8"
	trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>


<%@ attribute name="id" required="true" rtexprvalue="true"
	type="java.lang.String" description="id"%>

<%@ attribute name="tableName" required="true" rtexprvalue="true"
	type="java.lang.String" description="tableName"%>

<%@ attribute name="targetControlId" required="false" rtexprvalue="true"
	type="java.lang.String" description="targetControlId"%>

<%@ attribute name="targetIsEditor" required="false" rtexprvalue="true"
	type="java.lang.Boolean" description="targetControlId"%>

<%@ attribute name="useAsScript" required="false" rtexprvalue="true"
	type="java.lang.Boolean" description="targetControlId"%>

<div>
	<a class="nui-txt-link"
		href="javascript:$('#${id}entityVariableDialog').dialog('open');">插入实体变量
	</a>
</div>

<div id="${id}entityVariableDialog" title="插入实体变量">
	<div id="${id}entityVariableTab" class="box tabs">
		<div class="header">
			<ul>
				<li><a class="current" href="#${id}ProcessEntityField">业务表实体字段</a>
				</li>
			</ul>
			<h2>&nbsp;</h2>
		</div>
		<div style="padding:5px 15px" class="content tabbed">

			<div id="${id}EntityField"></div>

		</div>
	</div>
</div>
<script type="text/javascript">
	$("#${id}entityVariableTab").tabs();
	$("#${id}entityVariableDialog").dialog({
		autoOpen : false,
		width : 350,
		height : 400,

		buttons : {"关闭" : function() {
						$(this).dialog("close");
					}
				 }
		});
	
	$.getJSON("db/entityField/listByTableName?tableName=${tableName}",function(data){
		var html="<ul style='overflow:auto;height:290px'>";
	
		$(data).each(function(index,item){
			html+="<li><a class='nui-txt-link' href='javascript:${id}InsertToTargetControl(\"bpmBusinessModel."+item.column_name+"\");'>"+item.name+"</a></li>";
		});
	
		html+="</ul>";
		$("#${id}EntityField").html(html);
	});
	
</script>


<c:set var="varTxt" value="txt=\"$\"+\"{\"+txt+\"}\";">
</c:set>

<script type="text/javascript">
			function ${id}InsertToTargetControl(txt) {
				var myField = document.getElementById("${targetControlId}");
				${varTxt }
				//txt="$"+"{"+txt+"}";
				//IE support
				if (document.selection) {
					myField.focus();
					sel = document.selection.createRange();
					sel.text = txt;
					sel.select();
				}
				//MOZILLA/NETSCAPE support
				else if (myField.selectionStart || myField.selectionStart == '0') {
					var startPos = myField.selectionStart;
					var endPos = myField.selectionEnd;
					// save scrollTop before insert www.jbxue.com
					var restoreTop = myField.scrollTop;
					myField.value = myField.value.substring(0, startPos) + txt + myField.value.substring(endPos, myField.value.length);
					if (restoreTop > 0) {
						myField.scrollTop = restoreTop;
					}
					myField.focus();
					myField.selectionStart = startPos + txt.length;
					myField.selectionEnd = startPos + txt.length;
				} else {
					myField.value += txt;
					myField.focus();
				}

			}
		</script>
